********************************************************************************
* Robustness analysis: Workplace networks and political selection **************
********************************************************************************

clear all
clear matrix
set more off
set mat 10000
cd "E:/ProjData/Workplace, elite/"
capture log close
log using "C:/Userdata/Shared/Logs/Workplace, elite/robustness.text", replace text									
do "C:/Userdata/Shared/Dofiles/DoData/Workplace, elite/programs.do"		


use "finaldata.dta", clear

********************************************************************************
* Basic set-ups ****************************************************************
********************************************************************************

global covs "yearseducation zink"												
global wpssykcovslag "wpssyk_zink_lag wpssyk_yearseducation_lag wpssyk_gender_lag wpssyk_immig_lag"
global esttabbasic "replace label se nogaps b(5) compress booktabs nonotes star(* 0.1 ** 0.05 *** 0.01) varlabels(_cons "Constant") eqlabels(none)"
global depvar "i_nominated"
global indvar "maintreatvar"
global restriction "i_nominated_lag != 1 & i_nominated_lag2 != 1 & i_nominated_lag3 != 1 & i_nominated_lag4 != 1 & i_nominated_lag5 != 1" 	/*First time someone becomes a politician*/					

egen identificationvar = group(LopNr wp occupation) 							/* Main identification variable */

********************************************************************************
* LPM model for different municipal sizes **************************************
********************************************************************************


cumul muni_pop, gen(muni_pop_cdf)
gen muni_cat = 1 if muni_pop_cdf<0.20
replace muni_cat =2 if muni_pop_cdf>=0.20 & muni_pop_cdf<0.40
replace muni_cat =3 if muni_pop_cdf>=0.40 & muni_pop_cdf<0.60
replace muni_cat =4 if muni_pop_cdf>=0.60 & muni_pop_cdf<0.80
replace muni_cat =5 if muni_pop_cdf>=0.80 
replace muni_cat=. if muni_cat==.

eststo clear
eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction & muni_cat==1, absorb(identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
scalar bq1 = _b[$indvar]
scalar sdq1 = _se[$indvar]
scalar N1 = e(N)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"


eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction & muni_cat==2, absorb(identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
gen bq2 = _b[$indvar]
gen sdq2 = _se[$indvar]
gen N2 = e(N)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"


eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction & muni_cat==3, absorb(identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
gen bq3 = _b[$indvar]
gen sdq3 = _se[$indvar]
gen N3 = e(N)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"


eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction & muni_cat==4, absorb(identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
gen bq4 = _b[$indvar]
gen sdq4 = _se[$indvar]
gen N4 = e(N)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"


eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction & muni_cat==5, absorb(identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
gen bq5 = _b[$indvar]
gen sdq5 = _se[$indvar]
gen N5 = e(N)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"

#delimit ;
esttab using "C:/Userdata/Shared/Output/Workplace, elite/main_bymunipop.tex", 
$esttabbasic keep($indvar) stats(ymean modelt indwpoccu wpssykcovs covs mandate muni occutrend wptrend r2 pr2 N, fmt(4 0 0 0 0 0 0 0 0 3 3 0) 
label("Mean dep. var." "Regression model" "Individual*wp*occupation FE" "WP occupation covs t-1." "Individual covs t." "Mandate period FE" "Municipal FE" "Occupation mandate trend" "Workplace mandate trend" "R2" "Observations")) 
;
#delimit cr	

gen Q = _n
replace Q=. if Q>5

egen coef = min(bq1) if Q==1
foreach y of numlist 1(1)5 {
replace coef = bq`y' if Q==`y'
} 

gen upp = bq1+(1.96*sdq1) if Q==1
foreach y of numlist 1(1)5 {
replace upp = bq`y'+(1.96*sdq`y') if Q==`y'
} 

gen lower = bq1-(1.96*sdq1) if Q==1
foreach y of numlist 1(1)5 {
replace lower = bq`y'-(1.96*sdq`y') if Q==`y'
} 

* Create Figure
twoway rcap lower upp Q, lstyle(ci) || /// 
scatter coef Q , mstyle(pi) yline(0) xlabel(1 "<p20" 2 "p20-p40" 3 "p40-p60" 4 "p60-p80" 5 ">p80") ///
graphregion(color(white)) xtitle("Municipal group") ///
ytitle("Estimated coefficient") ///
legend(off)
graph export "C:/Userdata/Shared/Output/Workplace, elite/main_bymunipop.pdf", replace



********************************************************************************
* Placebo analyses *************************************************************
********************************************************************************

gen HsDeltD = .
replace HsDeltD = 0 if HsDelt == 0
replace HsDeltD = 1 if (HsDelt == 1 | HsDelt == 2 | HsDelt == 3)  				// College studies fall, spring and both fall spring semester. 

foreach k in LoneInk DispInk ForLed Akassa {
	replace `k' = `k' * 100														// Expressed in houndreds SEK
}

foreach k in LoneInk DispInk ForLed Akassa {										
	reg `k' i.year																// Compensate for inflation
	predict `k'_p, xb
}

foreach k in LoneInk DispInk ForLed Akassa {																		
	replace `k'_p = . if `k' < 1000	| `k' == .									// Considering the intensive margin above 1000 SEK
} 

foreach k in LoneInk_p DispInk_p ForLed_p Akassa_p {
	gen `k'_log = log(`k')														
}
 
foreach k in LoneInk_p_log DispInk_p_log ForLed_p_log Akassa_p_log yearseducation HsDeltD {
	bysort LopNr (mandatperiod): gen `k'_lag = `k'[_n-1] 
} 


label var LoneInk_p_log_lag "Lab.Inc"
label var DispInk_p_log_lag "Disp.Inc"
label var ForLed_p_log_lag "Par.Leave" 
label var Akassa_p_log_lag "UnemBen" 
label var yearseducation_lag "Y.educ"
label var HsDeltD_lag "College.P"
label var i_nominated_lag2 "l2.Nom"

eststo clear
eststo: reghdfe LoneInk_p_log_lag $indvar $wpssykcovslag if $restriction, absorb(i.identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
estadd ysumm
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"


eststo: reghdfe DispInk_p_log_lag $indvar $wpssykcovslag if $restriction, absorb(i.identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
estadd ysumm
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"


eststo: reghdfe ForLed_p_log_lag $indvar $wpssykcovslag if $restriction, absorb(i.identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
estadd ysumm
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"


eststo: reghdfe Akassa_p_log_lag  $indvar $wpssykcovslag if $restriction, absorb(i.identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
estadd ysumm
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"


eststo: reghdfe yearseducation_lag $indvar $wpssykcovslag if $restriction, absorb(i.identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
estadd ysumm
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"


eststo: reghdfe HsDeltD_lag $indvar $wpssykcovslag if $restriction, absorb(i.identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
estadd ysumm
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"

eststo: reghdfe i_nominated_lag2 $indvar $covs $wpssykcovslag if i_nominated_lag3 != 1 & i_nominated_lag4 != 1 & i_nominated_lag5 != 1, absorb(identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"



#delimit ;
esttab using "C:/Userdata/Shared/Output/Workplace, elite/placebo.tex", 
$esttabbasic keep($indvar) stats(ymean indwpoccu wpssykcovs covs mandate muni occutrend wptrend r2 N, fmt(3 0 0 0 0 0 0 0 3 0) 
label("Mean dep. var." "Individual*wp*occupation FE" "WP occupation covs t-1." "Individual covs t." "Mandate period FE" "Municipal FE" "Occupation mandate trend" "Workplace mandate trend" "R2" "Observations")) 
;
#delimit cr	



********************
* Workplace robustness


gen wpssyk_zink_lag2 = wpssyk_zink_lag[_n-1] 
gen wpssyk_yearseducation_lag2 = wpssyk_yearseducation_lag[_n-1]   
gen wpssyk_gender_lag2 = wpssyk_gender_lag[_n-1]   
gen wpssyk_immig_lag2 = wpssyk_immig_lag[_n-1]  


eststo clear
eststo: reghdfe wpssyk_zink_lag2 $indvar $covs if $restriction, absorb(i.identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
estadd ysumm
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"


eststo: reghdfe wpssyk_yearseducation_lag2 $indvar $covs if $restriction, absorb(i.identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
estadd ysumm
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"


eststo: reghdfe wpssyk_gender_lag2 $indvar $covs if $restriction, absorb(i.identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
estadd ysumm
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"


eststo: reghdfe wpssyk_immig_lag2 $indvar $covs if $restriction, absorb(i.identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
estadd ysumm
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"





#delimit ;
esttab using "C:/Userdata/Shared/Output/Workplace, elite/placebo_wp.tex", 
$esttabbasic keep($indvar) stats(ymean indwpoccu covs mandate muni occutrend wptrend r2 N, fmt(3 0 0 0 0 0 0 0 3 0) 
label("Mean dep. var." "Individual*wp*occupation FE" "WP occupation covs t-1." "Individual covs t." "Mandate period FE" "Municipal FE" "Occupation mandate trend" "Workplace mandate trend" "R2" "Observations")) 
;
#delimit cr	





********************************************************************************
* Partisan recruitment: Center-right + SD and center-left **********************
********************************************************************************

global partisanindvar "crsdtreatvar cltreatvar"

eststo clear
eststo: reg i_nominated_CRSD $partisanindvar if $restriction, cluster(identificationvar)
estadd ysumm 
estadd local modelt "LPM"
estadd local indwpoccu "No"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe i_nominated_CRSD $partisanindvar if $restriction, absorb(identificationvar) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local covs "No"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe i_nominated_CRSD $partisanindvar $covs $wpssykcovslag if $restriction, absorb(identificationvar mandatperiod Kkod) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe i_nominated_CRSD $partisanindvar $covs $wpssykcovslag if $restriction, absorb(identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"

eststo: clogit i_nominated_CRSD $partisanindvar if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm 
estadd local modelt "C. logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'

eststo: clogit i_nominated_CRSD $partisanindvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C. logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'


#delimit ;
esttab using "C:/Userdata/Shared/Output/Workplace, elite/panel_nom_CRSD.tex", 
$esttabbasic keep($partisanindvar) eform(0 0 0 0 1 1) stats(ymean modelt indwpoccu wpssykcovs covs mandate muni occutrend wptrend r2 pr2 N, fmt(4 0 0 0 0 0 0 0 0 3 3 0) 
label("Mean dep. var." "Regression model" "Individual*wp*occupation FE" "WP occupation covs t-1." "Individual covs t." "Mandate period FE" "Municipal FE" "Occupation mandate trend" "Workplace mandate trend" "R2" "Pseudo-R2" "Observations")) 
;
#delimit cr	

********************************************************************************
* Elected politician as dependent variable *************************************
********************************************************************************

eststo clear
eststo: reg i_elected $indvar if $restriction, cluster(identificationvar)
estadd ysumm 
estadd local modelt "LPM"
estadd local indwpoccu "No"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe i_elected $indvar if $restriction, absorb(identificationvar) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local covs "No"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe i_elected $indvar $covs $wpssykcovslag if $restriction, absorb(identificationvar mandatperiod Kkod) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe i_elected $indvar $covs $wpssykcovslag if $restriction, absorb(identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"

eststo: clogit i_elected $indvar if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm 
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'

eststo: clogit i_elected $indvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'



#delimit ;
esttab using "C:/Userdata/Shared/Output/Workplace, elite/panel_electeddep.tex", 
$esttabbasic keep($indvar) eform(0 0 0 0 1 1) stats(ymean modelt indwpoccu wpssykcovs covs mandate muni occutrend wptrend r2 pr2 N, fmt(4 0 0 0 0 0 0 0 0 3 3 0) 
label("Mean dep. var." "Regression model" "Individual*wp*occupation FE" "WP occupation covs t-1." "Individual covs t." "Mandate period FE" "Municipal FE" "Occupation mandate trend" "Workplace mandate trend" "R2" "Pseudo-R2" "Observations")) 
;
#delimit cr	




********************************************************************************
* List position cathegories: clogit ********************************************
********************************************************************************


*In t*
eststo clear
eststo: clogit top_al $indvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'


eststo: clogit safe_al $indvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'


eststo: clogit cmod_ab_al $indvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'


eststo: clogit chigh_al $indvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'


eststo: clogit cmod_bel_al $indvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'

eststo: clogit sloss_al $indvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'


#delimit ;
esttab using "C:/Userdata/Shared/Output/Workplace, elite/listposition_clogit.tex", 
$esttabbasic keep($indvar) eform(1 1 1 1 1 1) stats(ymean modelt indwpoccu wpssykcovs covs mandate muni occutrend wptrend r2 N, fmt(4 0 0 0 0 0 0 0 0 3 0) 
label("Mean dep. var." "Regression model" "Individual*wp*occupation FE" "WP occupation covs t-1." "Individual covs t." "Mandate period FE" "Municipal FE" "Occupation mandate trend" "Workplace mandate trend" "R2" "Observations")) 
;
#delimit cr	

*In t+1*
global restrictionlead "i_nominated_lag2 != 1 & i_nominated_lag3 != 1 & i_nominated_lag4 != 1 & i_nominated_lag5 != 1" 	/*First time someone becomes a politician*/					
foreach k in top_al safe_al cmod_ab_al chigh_al cmod_bel_al sloss_al {
	bysort LopNr (mandatperiod): gen `k'_lead = `k'[_n+1] 
}

label var top_al_lead "TopL1"															// This classification is based on Buisserets et al (2022) Party Nomination Strategies in List Proportional Representation Systems, AJPS 
label var safe_al_lead "SafeL1"
label var cmod_ab_al_lead "AdvantageL1" 
label var chigh_al_lead "HighlyL1" 
label var cmod_bel_al_lead "DisadL1." 
label var sloss_al_lead "Cert.LossL1" 


eststo clear
eststo: clogit top_al_lead $indvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'


eststo: clogit safe_al_lead $indvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'

eststo: clogit cmod_ab_al_lead $indvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'


eststo: clogit chigh_al_lead $indvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'


eststo: clogit cmod_bel_al_lead $indvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'

eststo: clogit sloss_al_lead $indvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'


#delimit ;
esttab using "C:/Userdata/Shared/Output/Workplace, elite/listposition_lead1_clogit.tex", 
$esttabbasic keep($indvar) eform(1 1 1 1 1 1)  stats(ymean modelt indwpoccu wpssykcovs covs mandate muni occutrend wptrend r2 N, fmt(4 0 0 0 0 0 0 0 0 3 0) 
label("Mean dep. var." "Regression model" "Individual*wp*occupation FE" "WP occupation covs t-1." "Individual covs t." "Mandate period FE" "Municipal FE" "Occupation mandate trend" "Workplace mandate trend" "R2" "Observations")) 
;
#delimit cr	

*t+2*
global restrictionlead2 "i_nominated_lag3 != 1 & i_nominated_lag4 != 1 & i_nominated_lag5 != 1" 	/*First time someone becomes a politician*/					
foreach k in top_al safe_al cmod_ab_al chigh_al cmod_bel_al sloss_al {
	bysort LopNr (mandatperiod): gen `k'_lead2 = `k'[_n+2] 
}

label var top_al_lead2 "TopL2"															// This classification is based on Buisserets et al (2022) Party Nomination Strategies in List Proportional Representation Systems, AJPS 
label var safe_al_lead2 "SafeL2"
label var cmod_ab_al_lead2 "AdvantageL2" 
label var chigh_al_lead2 "HighlyL2" 
label var cmod_bel_al_lead2 "DisadL2." 
label var sloss_al_lead2 "Cert.LossL2" 


eststo clear
eststo: clogit top_al_lead2 $indvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'


eststo: clogit safe_al_lead2 $indvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'


eststo: clogit cmod_ab_al_lead2 $indvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'


eststo: clogit chigh_al_lead2 $indvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'


eststo: clogit cmod_bel_al_lead2 $indvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'

eststo: clogit sloss_al_lead2 $indvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'


#delimit ;
esttab using "C:/Userdata/Shared/Output/Workplace, elite/listposition_lead2_clogit.tex", 
$esttabbasic keep($indvar) eform(1 1 1 1 1 1)  stats(ymean modelt indwpoccu wpssykcovs covs mandate muni occutrend wptrend r2 N, fmt(4 0 0 0 0 0 0 0 0 3 0) 
label("Mean dep. var." "Regression model" "Individual*wp*occupation FE" "WP occupation covs t-1." "Individual covs t." "Mandate period FE" "Municipal FE" "Occupation mandate trend" "Workplace mandate trend" "R2" "Observations")) 
;
#delimit cr	


********************************************************************************
* Elected politician as independent variable ***********************************
********************************************************************************

global indvarelect "electvar"

eststo clear
eststo: reg $depvar $indvarelect if $restriction, cluster(identificationvar)
estadd ysumm 
estadd local modelt "LPM"
estadd local indwpoccu "No"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar $indvarelect if $restriction, absorb(identificationvar) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local covs "No"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar  $indvarelect $covs $wpssykcovslag if $restriction, absorb(identificationvar mandatperiod Kkod) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction, absorb(identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"

eststo: clogit $depvar  $indvarelect if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm 
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'

eststo: clogit $depvar  $indvarelect $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'



#delimit ;
esttab using "C:/Userdata/Shared/Output/Workplace, elite/panel_elect.tex", 
$esttabbasic keep($indvarelect) eform(0 0 0 0 1 1) stats(ymean modelt indwpoccu wpssykcovs covs mandate muni occutrend wptrend r2 pr2 N, fmt(4 0 0 0 0 0 0 0 0 3 3 0) 
label("Mean dep. var." "Regression model" "Individual*wp*occupation FE" "WP occupation covs t-1." "Individual covs t." "Mandate period FE" "Municipal FE" "Occupation mandate trend" "Workplace mandate trend" "R2" "Pseudo-R2" "Observations")) 
;
#delimit cr	



																
********************************************************************************
* Removing politician close occupations  ***************************************
********************************************************************************



/* 111 = professional politicians and high civil servants */
/* 242 = lobbyist/Ombudsman*/
/* 124 = PR executive*/
/* 243 = PR consultant*/
/* 411 = PR assistant*/
/* 443 = Förtroendeman/förtroendevald */


global ssykrestrict1 "ssyk_3str != "111" & ssyk_3str != "242" & ssyk_3str != "124" & ssyk_3str != "243" & ssyk_3str != "411" & ssyk_3str != "443""

eststo clear
eststo: reg $depvar $indvar if $restriction & $ssykrestrict1, cluster(identificationvar)
estadd ysumm 
estadd local modelt "LPM"
estadd local indwpoccu "No"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar $indvar if $restriction & $ssykrestrict1, absorb(identificationvar) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local covs "No"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction & $ssykrestrict1, absorb(identificationvar mandatperiod Kkod) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction & $ssykrestrict1, absorb(identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"

eststo: clogit $depvar $indvar if $restriction & $ssykrestrict1, group(identificationvar) cluster(identificationvar) or 
estadd ysumm 
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'

eststo: clogit $depvar $indvar $covs $wpssykcovslag if $restriction & $ssykrestrict1, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'



#delimit ;
esttab using "C:/Userdata/Shared/Output/Workplace, elite/panel_nom_nonpol1.tex", 
$esttabbasic keep($indvar) eform(0 0 0 0 1 1) stats(ymean modelt indwpoccu wpssykcovs covs mandate muni occutrend wptrend r2 pr2 N, fmt(4 0 0 0 0 0 0 0 0 3 3 0) 
label("Mean dep. var." "Regression model" "Individual*wp*occupation FE" "WP occupation covs t-1." "Individual covs t." "Mandate period FE" "Municipal FE" "Occupation mandate trend" "Workplace mandate trend" "R2" "Pseudo-R2" "Observations")) 
;
#delimit cr	




********************************************************************************
**Politician profession and 5 most common professions **************************
********************************************************************************

* Calculate most common professions among all politicians *
/*
use "politicians_mod", clear

merge 1:1 LopNr year using "arbetstalle_panel", nogen keep(1 3)
replace ssyk = "" if ssyk == "****"
gen ssyk_3str = substr(ssyk, 1,3)  

egen mode1 = mode(ssyk_3str)								/*Bartender barista*/

replace ssyk_3str = "" if ssyk_3str == mode1				
egen mode2 = mode(ssyk_3str)								/*Folkskolelärare*/								

replace ssyk_3str = "" if ssyk_3str == mode2				
egen mode3 = mode(ssyk_3str)								

replace ssyk_3str = "" if ssyk_3str == mode3				
egen mode4 = mode(ssyk_3str)								/*Gymnasielärare*/

replace ssyk_3str = "" if ssyk_3str == mode4				
egen mode5 = mode(ssyk_3str)								/*Mellanchef*/

forvalues k = 1(1)5 {
	display mode`k' 										/*5 most common professions among politicians*/
}
*/

global ssykrestrict2 "ssyk_3str != "513" & ssyk_3str != "233" & ssyk_3str != "247" & ssyk_3str != "232" & ssyk_3str != "131" & ssyk_3str != "111" & ssyk_3str != "242" & ssyk_3str != "124" & ssyk_3str != "243" & ssyk_3str != "411" & ssyk_3str != "443""

eststo clear
eststo: reg $depvar $indvar if $restriction & $ssykrestrict2, cluster(identificationvar)
estadd ysumm 
estadd local modelt "LPM"
estadd local indwpoccu "No"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar $indvar if $restriction & $ssykrestrict2, absorb(identificationvar) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local covs "No"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction & $ssykrestrict2, absorb(identificationvar mandatperiod Kkod) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction & $ssykrestrict2, absorb(identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"

eststo: clogit $depvar $indvar if $restriction & $ssykrestrict2, group(identificationvar) cluster(identificationvar) or 
estadd ysumm 
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'

eststo: clogit $depvar $indvar $covs $wpssykcovslag if $restriction & $ssykrestrict2, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'



#delimit ;
esttab using "C:/Userdata/Shared/Output/Workplace, elite/panel_nom_nonpol2.tex", 
$esttabbasic keep($indvar) eform(0 0 0 0 1 1) stats(ymean modelt indwpoccu wpssykcovs covs mandate muni occutrend wptrend r2 pr2 N, fmt(4 0 0 0 0 0 0 0 0 3 3 0) 
label("Mean dep. var." "Regression model" "Individual*wp*occupation FE" "WP occupation covs t-1." "Individual covs t." "Mandate period FE" "Municipal FE" "Occupation mandate trend" "Workplace mandate trend" "R2" "Pseudo-R2" "Observations")) 
;
#delimit cr	




********************************************************************************
* Size of the workplace ********************************************************
********************************************************************************

eststo clear
clear matrix
forvalues k = 10(20)150 {																
	preserve
	reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction & N_wpssyk_lag <= `k', absorb(identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
	matrix define a=e(b)														
	scalar define a1=a[1,1]
	matrix define v=e(V)
	scalar define v1=sqrt(v[1,1])												
	scalar define upper=a1+1.96*v1												// Conventional standard errors												
	scalar define lower=a1-1.96*v1
	scalar define bandwidth=`k'
	matrix define rd = [nullmat(rd)\bandwidth,a1,upper,lower]
	restore
}
svmat rd
preserve
keep rd1 rd2 rd3 rd4 
drop if rd1 == .
graph twoway (line rd2 rd1, lcolor(black)) (line rd3 rd1, lpattern(dash) lcolor(gs8)) (line rd4 rd1, lpattern(dash) lcolor(gs8)), graphregion(color(white)) xlabel(0(25)150) legend(order(1 "Point estimate" 2 "95 % CI") region(col(white))) ytitle("Estimated coefficient") xtitle("Number of employees")
graph export "C:/Userdata/Shared/Output/Workplace, elite/nominated_Nemployees.pdf", replace 
restore
drop rd*



********************************************************************************
* Size of the workplace 2 ********************************************************
********************************************************************************

*Max and min number in cell
bysort identificationvar: egen treat_1 = max(N_wpssyk_lag)
bysort identificationvar: egen treat_2 = min(N_wpssyk_lag)


eststo clear
eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction & treat_1<=5 & treat_2>=3, absorb(identificationvar) cluster(identificationvar)
scalar wpbq1 = _b[$indvar]
scalar wpsdq1 = _se[$indvar]
scalar wpN1 = e(N)


eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction & treat_1<=8 & treat_2>=6, absorb(identificationvar) cluster(identificationvar)
gen wpbq2 = _b[$indvar]
gen wpsdq2 = _se[$indvar]
gen wpN2 = e(N)


eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction & treat_1<=11 & treat_2>=9, absorb(identificationvar) cluster(identificationvar)
gen wpbq3 = _b[$indvar]
gen wpsdq3 = _se[$indvar]
gen wpN3 = e(N)


eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction & treat_1<=15 & treat_2>=12, absorb(identificationvar) cluster(identificationvar)
gen wpbq4 = _b[$indvar]
gen wpsdq4 = _se[$indvar]
gen wpN4 = e(N)

eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction, absorb(identificationvar) cluster(identificationvar)
gen wpbq5 = _b[$indvar]
gen wpsdq5 = _se[$indvar]
gen wpN5 = e(N)


gen wpQ = _n
replace wpQ=. if wpQ>5

egen wpcoef = min(wpbq1) if wpQ==1
foreach y of numlist 1(1)5 {
replace wpcoef = wpbq`y' if wpQ==`y'
} 

gen wpupp = wpbq1+(1.96*wpsdq1) if wpQ==1
foreach y of numlist 1(1)5 {
replace wpupp = wpbq`y'+(1.96*wpsdq`y') if wpQ==`y'
} 

gen wplower = wpbq1-(1.96*wpsdq1) if wpQ==1
foreach y of numlist 1(1)5 {
replace wplower = wpbq`y'-(1.96*wpsdq`y') if wpQ==`y'
} 

* Create Figure
twoway rcap wplower wpupp wpQ, lstyle(ci) || /// 
scatter wpcoef wpQ , mstyle(pi) yline(0) xlabel(1 "3-5" 2 "6-8" 3 "9-11" 4 "12-15" 5 "All WP:s") ///
graphregion(color(white)) xtitle("Size of cells") ///
ytitle("Estimated coefficient") ///
legend(off)
graph export "C:/Userdata/Shared/Output/Workplace, elite/wp_similarcells.pdf", replace




********************************************************************************
* Heterogeneity analysis: Interactions *****************************************
********************************************************************************

global interindvarscr "crtreatvar crd intercr"
global interindvarscl "cltreatvar cld intercl"


eststo clear
eststo: reg i_nominated_CR $interindvarscr if $restriction, cluster(identificationvar)
estadd ysumm 
estadd local modelt "LPM"
estadd local indwpoccu "No"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe i_nominated_CR $interindvarscr if $restriction, absorb(identificationvar) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local covs "No"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe i_nominated_CR $interindvarscr $covs $wpssykcovslag if $restriction, absorb(identificationvar mandatperiod Kkod) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe i_nominated_CR $interindvarscr $covs $wpssykcovslag if $restriction, absorb(identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"

eststo: clogit i_nominated_CR $interindvarscr if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm 
estadd local modelt "C. logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'

eststo: clogit i_nominated_CR $interindvarscr $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C. logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'


#delimit ;
esttab using "C:/Userdata/Shared/Output/Workplace, elite/nom_interCR.tex", 
$esttabbasic keep($interindvarscr) eform(0 0 0 0 1 1) stats(ymean modelt indwpoccu wpssykcovs covs mandate muni occutrend wptrend r2 pr2 N, fmt(4 0 0 0 0 0 0 0 0 3 3 0) 
label("Mean dep. var." "Regression model" "Individual*wp*occupation FE" "WP occupation covs t-1." "Individual covs t." "Mandate period FE" "Municipal FE" "Occupation mandate trend" "Workplace mandate trend" "R2" "Pseudo-R2" "Observations")) 
;
#delimit cr	


eststo clear
eststo: reg i_nominated_CL $interindvarscl if $restriction, cluster(identificationvar)
estadd ysumm 
estadd local modelt "LPM"
estadd local indwpoccu "No"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe i_nominated_CL $interindvarscl if $restriction, absorb(identificationvar) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local covs "No"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe i_nominated_CL $interindvarscl $covs $wpssykcovslag if $restriction, absorb(identificationvar mandatperiod Kkod) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe i_nominated_CL $interindvarscl $covs $wpssykcovslag if $restriction, absorb(identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"

eststo: clogit i_nominated_CL $interindvarscl if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm 
estadd local modelt "C. logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'

eststo: clogit i_nominated_CL $interindvarscl $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C. logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'


#delimit ;
esttab using "C:/Userdata/Shared/Output/Workplace, elite/nom_interCL.tex", 
$esttabbasic keep($interindvarscl) eform(0 0 0 0 1 1) stats(ymean modelt indwpoccu wpssykcovs covs mandate muni occutrend wptrend r2 pr2 N, fmt(4 0 0 0 0 0 0 0 0 3 3 0) 
label("Mean dep. var." "Regression model" "Individual*wp*occupation FE" "WP occupation covs t-1." "Individual covs t." "Mandate period FE" "Municipal FE" "Occupation mandate trend" "Workplace mandate trend" "R2" "Pseudo-R2" "Observations")) 
;
#delimit cr	


********************************************************************************
* Analysis without large values in the independent variable ********************
********************************************************************************

gen restrictvar = 0
sum $indvar, detail
replace restrictvar = 1 if $indvar >= `r(p95)' & $indvar != .
bysort LopNr: egen restrictvarmean = mean(restrictvar)							// Dropping the entire indiviudal
global outlierrestrict "restrictvarmean == 0" 

eststo clear
eststo: reg $depvar $indvar if $restriction & $outlierrestrict, cluster(identificationvar)
estadd ysumm 
estadd local modelt "LPM"
estadd local indwpoccu "No"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar $indvar if $restriction & $outlierrestrict, absorb(identificationvar) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local covs "No"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction & $outlierrestrict, absorb(identificationvar mandatperiod Kkod) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction & $outlierrestrict, absorb(identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"

eststo: clogit $depvar $indvar if $restriction & $outlierrestrict, group(identificationvar) cluster(identificationvar) or 
estadd ysumm 
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'

eststo: clogit $depvar $indvar $covs $wpssykcovslag if $restriction & $outlierrestrict, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'



#delimit ;
esttab using "C:/Userdata/Shared/Output/Workplace, elite/panel_nom_outlier.tex", 
$esttabbasic keep($indvar) eform(0 0 0 0 1 1) stats(ymean modelt indwpoccu wpssykcovs covs mandate muni occutrend wptrend r2 pr2 N, fmt(4 0 0 0 0 0 0 0 0 3 3 0) 
label("Mean dep. var." "Regression model" "Individual*wp*occupation FE" "WP occupation covs t-1." "Individual covs t." "Mandate period FE" "Municipal FE" "Occupation mandate trend" "Workplace mandate trend" "R2" "Pseudo-R2" "Observations")) 
;
#delimit cr	


********************************************************************************
* Analysis using the number of politican collegues********* ********************
********************************************************************************

eststo clear
eststo: reg $depvar s_wpssyk_nominated_lag if $restriction, cluster(identificationvar)
estadd ysumm 
estadd local modelt "LPM"
estadd local indwpoccu "No"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar s_wpssyk_nominated_lag if $restriction, absorb(identificationvar) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local covs "No"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar s_wpssyk_nominated_lag $covs $wpssykcovslag if $restriction, absorb(identificationvar mandatperiod Kkod) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar s_wpssyk_nominated_lag $covs $wpssykcovslag if $restriction, absorb(identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(identificationvar)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"

eststo: clogit $depvar s_wpssyk_nominated_lag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm 
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'

eststo: clogit $depvar s_wpssyk_nominated_lag $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(identificationvar) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'



#delimit ;
esttab using "C:/Userdata/Shared/Output/Workplace, elite/numberpols.tex", 
$esttabbasic keep(s_wpssyk_nominated_lag) eform(0 0 0 0 1 1) stats(ymean modelt indwpoccu wpssykcovs covs mandate muni occutrend wptrend r2 pr2 N, fmt(4 0 0 0 0 0 0 0 0 3 3 0) 
label("Mean dep. var." "Regression model" "Individual*wp*occupation FE" "WP occupation covs t-1." "Individual covs t." "Mandate period FE" "Municipal FE" "Occupation mandate trend" "Workplace mandate trend" "R2" "Pseudo-R2" "Observations")) 
;
#delimit cr	



********************************************************************************
* Other clustering levels of the standard errors******************************** 
********************************************************************************

*Clustering on the workplace level*

eststo clear
eststo: reg $depvar $indvar if $restriction, cluster(wp)
estadd ysumm 
estadd local modelt "LPM"
estadd local indwpoccu "No"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar $indvar if $restriction, absorb(identificationvar) cluster(wp)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local covs "No"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction, absorb(identificationvar mandatperiod Kkod) cluster(wp)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction, absorb(identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(wp)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"

eststo: clogit $depvar $indvar if $restriction, group(identificationvar) cluster(wp) or nonest
estadd ysumm 
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'

eststo: clogit $depvar $indvar $covs $wpssykcovslag if $restriction, group(identificationvar) cluster(wp) or nonest 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'




#delimit ;
esttab using "C:/Userdata/Shared/Output/Workplace, elite/cluster_wp.tex", 
$esttabbasic keep($indvar) eform(0 0 0 0 1 1) stats(ymean modelt indwpoccu wpssykcovs covs mandate muni occutrend wptrend r2 pr2 N, fmt(4 0 0 0 0 0 0 0 0 3 3 0) 
label("Mean dep. var." "Regression model" "Individual*wp*occupation FE" "WP occupation covs t-1." "Individual covs t." "Mandate period FE" "Municipal FE" "Occupation mandate trend" "Workplace mandate trend" "R2" "Pseudo-R2" "Observations")) 
;
#delimit cr	


*Clustering on the muncipal level*
eststo clear
eststo: reg $depvar $indvar if $restriction & Kkod != ., cluster(Kkod)
estadd ysumm 
estadd local modelt "LPM"
estadd local indwpoccu "No"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar $indvar if $restriction & Kkod != ., absorb(identificationvar) cluster(Kkod)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local covs "No"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction & Kkod != ., absorb(identificationvar mandatperiod Kkod) cluster(Kkod)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "No"
estadd local wptrend "No"

eststo: reghdfe $depvar $indvar $covs $wpssykcovslag if $restriction & Kkod != ., absorb(identificationvar mandatperiod##occupation mandatperiod##wp Kkod) cluster(Kkod)
estadd ysumm
estadd local modelt "LPM"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local occutrend "Yes"
estadd local wptrend "Yes"

eststo: clogit $depvar $indvar if $restriction & Kkod != ., group(identificationvar) cluster(Kkod) or nonest
estadd ysumm 
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'

eststo: clogit $depvar $indvar $covs $wpssykcovslag if $restriction & Kkod != ., group(identificationvar) cluster(Kkod) or nonest
estadd ysumm
estadd local modelt "C.logit"
estadd local indwpoccu "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local occutrend "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'



#delimit ;
esttab using "C:/Userdata/Shared/Output/Workplace, elite/cluster_muni.tex", 
$esttabbasic keep($indvar) eform(0 0 0 0 1 1) stats(ymean modelt indwpoccu wpssykcovs covs mandate muni occutrend wptrend r2 pr2 N, fmt(4 0 0 0 0 0 0 0 0 3 3 0) 
label("Mean dep. var." "Regression model" "Individual*wp*occupation FE" "WP occupation covs t-1." "Individual covs t." "Mandate period FE" "Municipal FE" "Occupation mandate trend" "Workplace mandate trend" "R2" "Pseudo-R2" "Observations")) 
;
#delimit cr	


********************************************************************************
* Treatment at smaller workplaces (not workplace-occupation cells) 
********************************************************************************

egen identificationvarindwp = group(LopNr wp) 									// Only workplace indiviudal fixed effects. 							


eststo clear
eststo: reg $depvar wptreatvar if $restriction & N_wp_id_lag < 50, cluster(identificationvarindwp)
estadd ysumm 
estadd local modelt "LPM"
estadd local indwp "No"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local wptrend "No"

eststo: reghdfe $depvar wptreatvar if $restriction & N_wp_id_lag < 50, absorb(identificationvarindwp) cluster(identificationvarindwp)
estadd ysumm
estadd local modelt "LPM"
estadd local indwp "Yes"
estadd local wpssykcovs "No" 
estadd local covs "No"
estadd local mandate "No"
estadd local muni "No" 
estadd local wptrend "No"

eststo: reghdfe $depvar wptreatvar $covs $wpssykcovslag if $restriction & N_wp_id_lag < 50, absorb(identificationvarindwp mandatperiod Kkod) cluster(identificationvarindwp)
estadd ysumm
estadd local modelt "LPM"
estadd local indwp "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local wptrend "No"

eststo: reghdfe $depvar wptreatvar $covs $wpssykcovslag if $restriction & N_wp_id_lag < 50, absorb(identificationvarindwp mandatperiod##wp Kkod) cluster(identificationvarindwp)
estadd ysumm
estadd local modelt "LPM"
estadd local indwp "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "Yes"
estadd local muni "Yes" 
estadd local wptrend "Yes"

eststo: clogit $depvar wptreatvar if $restriction & N_wp_id_lag < 50, group(identificationvarindwp) cluster(identificationvarindwp) or 
estadd ysumm 
estadd local modelt "C.logit"
estadd local indwp "Yes"
estadd local wpssykcovs "No" 
estadd local muni "No" 
estadd local mandate "No"
estadd local covs "No"
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'

eststo: clogit $depvar wptreatvar $covs $wpssykcovslag if $restriction & N_wp_id_lag < 50, group(identificationvarindwp) cluster(identificationvarindwp) or 
estadd ysumm
estadd local modelt "C.logit"
estadd local indwp "Yes"
estadd local wpssykcovs "Yes" 
estadd local covs "Yes"
estadd local mandate "No"
estadd local muni "No" 
estadd local wptrend "No"
estadd scalar pr2 `e(r2_p)'



#delimit ;
esttab using "C:/Userdata/Shared/Output/Workplace, elite/wp50.tex", 
$esttabbasic keep(wptreatvar) eform(0 0 0 0 1 1) stats(ymean modelt indwp wpssykcovs covs mandate muni wptrend r2 pr2 N, fmt(4 0 0 0 0 0 0 0 3 3 0) 
label("Mean dep. var." "Regression model" "Individual*wp* FE" "WP occupation covs t-1." "Individual covs t." "Mandate period FE" "Municipal FE" "Workplace mandate trend" "R2" "Pseudo-R2" "Observations")) 
;
#delimit cr	

***
clear all
clear matrix
capture log close

